package inet.app.controller.parser;


import inet.app.controller.connect.JsonParser;
import inet.app.model.object.Somo_Item;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

public class Parser_Somo {

	private ArrayList<Somo_Item> list = new ArrayList<Somo_Item>();
	private Somo_Item item;
	private String ITEMS = "items";
	private String ID ="id";
	private String NAME = "name";
	private String NUMBER = "number";
	
	
	public Parser_Somo () {
		
	}
	public ArrayList<Somo_Item> getList(String url) {
		list = new ArrayList<Somo_Item>();
		JSONObject jobject,object,job_items;
		JsonParser jParser = new JsonParser();
		jobject = jParser.getJSONFromUrl(url);
		try {
				JSONArray ja = jobject.getJSONArray(ITEMS);
				int i = 0;
				String name,numbers;
				int id;
				
				for (i = 0; i < ja.length(); i++) {
					object = ja.getJSONObject(i);
					id = object.getInt(ID);
					name= object.getString(NAME);
					numbers = object.getString(NUMBER);
					item = new Somo_Item(id, name, numbers);
					list.add(item);
				}
			return list;
        } catch (Exception e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
            return null;
        }
		
	}
	public ArrayList<Somo_Item> getListSomo(String url) {
		list = new ArrayList<Somo_Item>();
		JSONObject jobject,object;
		try {
			jobject = new JSONObject(url);
				JSONArray ja = jobject.getJSONArray(ITEMS);
				int i = 0;
				String name,numbers;
				int id;
				
				for (i = 0; i < ja.length(); i++) {
					object = ja.getJSONObject(i);
					id = object.getInt(ID);
					name= object.getString(NAME);
					numbers = object.getString(NUMBER);
					item = new Somo_Item(id, name, numbers);
					list.add(item);
				}
			return list;
        } catch (Exception e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
            return null;
        }
		
	}
}
